var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        };
Object.defineProperty(o, "__esModule", {value: !0}), (o.JieriHuodong = void 0);
var a = t("Counter"),
    i = t("WatchVideo"),
    s = t("Const"),
    c = t("LoadImgs"),
    l = t("Platforms"),
    u = t("Popup"),
    p = t("Sounds"),
    f = t("TableRules"),
    d = t("JieriChest"),
    h = t("BootConst"),
    y = t("ConfS"),
    g = cc._decorator,
    v = g.ccclass,
    m =
        (g.property,
        (function (t) {
            function e() {
                return (null !== t && t.apply(this, arguments)) || this;
            }
            var o;
            return (
                n(e, t),
                (o = e),
                (e.prototype.init = function () {
                    var t = this;
                    l.default.userStorage.节日日子 == y.DatasManager.节日活动开始时间 ||
                        ((l.default.userStorage.节日日子 = y.DatasManager.节日活动开始时间),
                        (l.default.userStorage.已阅读节日文案 = !1)),
                        (this.bg = this.node.getChildByName("bg")),
                        (this.info = this.node.getChildByName("info").getComponent(cc.Label)),
                        (this.title = this.node.getChildByName("title").getComponent(cc.Sprite)),
                        (this._time = this.node.getChildByName("time")),
                        (this.time = this._time.getChildByName("txt").getComponent(cc.Label));
                    var e = y.DatasManager.节日活动开始时间.match(/(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/),
                        n = new Date(
                            parseInt(e[1]),
                            parseInt(e[2]) - 1,
                            parseInt(e[3]),
                            parseInt(e[4]),
                            parseInt(e[5]),
                            parseInt(e[6])
                        ),
                        r = new Date();
                    o.startSec = Math.ceil(n.getTime() / 1e3);
                    var u = Math.ceil(r.getTime() / 1e3),
                        f = o.startSec - u;
                    f > 0
                        ? ((this.counter = new a.default()),
                          this.counter.init(f, function (e) {
                              (t.time.string = l.default.formatTime(e, !0, !0)),
                                  l.default.节日活动按钮 && (l.default.节日活动按钮.time.string = t.time.string);
                          }),
                          this.counter.start(function () {
                              (t.counter = null),
                                  (t._time.active = !1),
                                  l.default.节日活动按钮 && l.default.节日活动按钮.shake();
                          }))
                        : (this._time.active = !1),
                        f < 86400 * -y.DatasManager.节日活动持续天数 ||
                            c.LoadImgs.load(s.default.url_prefix_share + y.DatasManager.节日活动标题, !0, function (e) {
                                t.title.spriteFrame = e;
                            });
                    var g = y.DatasManager.节日活动节点.replace(/^\s*|\s*$/g, "").split(/\s*\n\s*/),
                        v = this.node.getChildByName("chests");
                    this.chests = new Array();
                    for (var m = -1, _ = 0, A = v.children; _ < A.length; _++) {
                        var b = A[_];
                        m++, l.default.userStorage.节日宝箱[m] || (l.default.userStorage.节日宝箱[m] = "未打开");
                        var C = g[m],
                            w = C.match(/^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)$/);
                        if (w) {
                            var O = l.default.prefabs.instantiate("节日宝箱").getComponent(d.default);
                            b.addChild(O.node),
                                this.chests.push(O),
                                O.init(m, w[1], w[2], parseInt(w[3]), parseInt(w[4])),
                                O.node.on(cc.Node.EventType.TOUCH_END, function (e) {
                                    if (t.counter) l.default.platformCtrl.toast(y.DatasManager.节日活动未开始);
                                    else
                                        switch (
                                            ((t.currChest = e.target.getComponent(d.default)),
                                            console.log(l.default.userStorage.节日宝箱[t.currChest.index]),
                                            l.default.userStorage.节日宝箱[t.currChest.index])
                                        ) {
                                            case "未打开":
                                                var n = Math.ceil(new Date().getTime() / 1e3);
                                                o.startSec - n < 86400 * -y.DatasManager.节日活动持续天数
                                                    ? l.default.platformCtrl.toast(y.DatasManager.节日活动已结束)
                                                    : i.default.show(h.dd.jieriHuodong, function () {
                                                          (l.default.userStorage.节日宝箱[t.currChest.index] =
                                                              "已打开"),
                                                              l.default.userStorage.setDirty(),
                                                              t.currChest.open(function () {
                                                                  t.refresh();
                                                              });
                                                      });
                                                break;
                                            case "已打开":
                                                (l.default.userStorage.节日宝箱[t.currChest.index] = "已领取"),
                                                    t.currChest.gems > 0 &&
                                                        s.default.addMoney(
                                                            "钻石",
                                                            t.currChest.gems,
                                                            "节日活动",
                                                            t.currChest.node,
                                                            null
                                                        ),
                                                    t.currChest.coins > 0 &&
                                                        s.default.addMoney(
                                                            "金币",
                                                            t.currChest.coins,
                                                            "节日活动",
                                                            t.currChest.node,
                                                            null
                                                        ),
                                                    l.default.userStorage.setDirty(),
                                                    t.refresh();
                                                break;
                                            case "已领取":
                                                l.default.platformCtrl.toast(
                                                    "已领过“" + t.currChest.name1 + "”的礼物，明天再来吧！"
                                                );
                                        }
                                });
                        } else console.error("匹配失败：" + C);
                    }
                    if (
                        ((this.close = this.node.getChildByName("close")),
                        this.close.on(cc.Node.EventType.TOUCH_END, function () {
                            p.Sounds.playFX("点击"), t.hide();
                        }),
                        s.default.wid0 > s.default.hei0)
                    );
                    else {
                        (this.bg.angle = v.angle = -90), (this.bg.y = v.y = -40);
                        for (var P = 0, S = v.children; P < S.length; P++) {
                            (b = S[P]).angle = 90;
                        }
                        this.node.height = 1200;
                    }
                }),
                (e.prototype.refresh = function () {
                    for (var t = 0, e = this.chests; t < e.length; t++) {
                        e[t].refresh();
                    }
                }),
                (e.prototype.show = function () {
                    var e = this;
                    if (
                        (t.prototype.show.call(this),
                        f.TableRules.pause(),
                        this.refresh(),
                        l.default.userStorage.已阅读节日文案)
                    )
                        this.info.node.active = !1;
                    else {
                        (l.default.userStorage.已阅读节日文案 = !0),
                            l.default.userStorage.setDirty(),
                            p.Sounds.stopMusic(),
                            (this.bg.opacity = 0),
                            (this.info.string = ""),
                            (this.info.node.active = !0),
                            (this.title.node.opacity = 0),
                            (this._time.opacity = 0),
                            (this.close.active = !1);
                        for (var o = 0, n = this.chests; o < n.length; o++) {
                            n[o].node.opacity = 0;
                        }
                        var r = y.DatasManager.节日活动文案.replace(/^\s*|\s*$/g, "").split(/\s*\n\s*/),
                            a = function () {
                                r.length
                                    ? "${stars}" == r[0]
                                        ? e.bg.runAction(
                                              cc.sequence(
                                                  cc.fadeIn(1),
                                                  cc.delayTime(0.5),
                                                  cc.callFunc(function () {
                                                      var t = -1,
                                                          o = function () {
                                                              ++t >= e.chests.length
                                                                  ? (r.splice(0, 1), a())
                                                                  : e.chests[t].node.runAction(
                                                                        cc.sequence(
                                                                            cc.fadeIn(1),
                                                                            cc.delayTime(0.5),
                                                                            cc.callFunc(o)
                                                                        )
                                                                    );
                                                          };
                                                      o();
                                                  })
                                              )
                                          )
                                        : e.info.node.runAction(
                                              cc.sequence(
                                                  cc.fadeOut(0.2),
                                                  cc.callFunc(function () {
                                                      (e.info.string = r[0]), r.splice(0, 1);
                                                  }),
                                                  cc.fadeIn(1),
                                                  cc.delayTime(0.5),
                                                  cc.callFunc(a)
                                              )
                                          )
                                    : l.default.delays.delay({
                                          time: 2,
                                          action: function () {
                                              (e.info.node.active = !1),
                                                  (e.title.node.opacity = 255),
                                                  (e._time.opacity = 255),
                                                  (e.close.active = !0),
                                                  p.Sounds.playMusic("主界面");
                                          }
                                      });
                            };
                        l.default.delays.delay({
                            time: 1,
                            action: function () {
                                a();
                            }
                        });
                    }
                }),
                (e.prototype.showComplete = function () {
                    t.prototype.showComplete.call(this);
                }),
                (e.prototype.hide = function () {
                    t.prototype.hide.call(this);
                }),
                (e.prototype.hideComplete = function () {
                    t.prototype.hideComplete.call(this), f.TableRules.resume();
                }),
                (e = o = r([v], e))
            );
        })(u.Popup));
o.JieriHuodong = m;
